package com.unionftech.common.permissions.tip.bean;

import android.content.Context;

import com.unionftech.baselibrary.base.BaseApplication;
import com.unionftech.common.common.language.DynamicResourceManager;
import com.unionftech.common.utils.Utils;

import java.util.List;

/**
 * 该类对应res/raw目录下的权限场景说明信息json文件中的一个json对象
 * {
 * "androidPermissionsNames": [
 * Manifest.permission.WRITE_EXTERNAL_STORAGE,
 * Manifest.permission.READ_EXTERNAL_STORAGE
 * ],
 * "showPermissionNameKey": "string_photo_library_title",
 * "showPermissionDescKey": "string_photo_library_desc",
 * }
 */
public class PermissionInfoForJson {
    private List<String> androidPermissionNames;
    private String showPermissionNameKey;
    private String showPermissionDescKey;

    public PermissionTipInfo changeToPermissionTipInfo(Context context, String permission) {
        if (androidPermissionNames.contains(permission)) {
            String showPermissionName = getStringResourceByName(context, this.showPermissionNameKey);
            String showPermissionDesc = getStringResourceByName(context, this.showPermissionDescKey);
            String title = Utils.getAppName(BaseApplication.appContext);
            return new PermissionTipInfo(title + showPermissionName, showPermissionDesc);
        }
        return null;
    }

    private String getStringResourceByName(Context context, String name) {
        return DynamicResourceManager.getString(context, name);
    }
}
